﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Org.Eurekaa.DNJ.UI.WebControls
{
    public class DNJSettings : Hashtable
    {

        public override string ToString()
        {
            string str = "";
            foreach (object key in this.Keys)
            {
                object val = this[key];

                if (String.IsNullOrEmpty(str)) str = "{";
                else str += ",";

                str += key.ToString() + ":";

                str += ToStrByType(val);
            }
            if (!String.IsNullOrEmpty(str)) str += "}";

            return str;
        }

        private String ToStrByType(object obj)
        {
            if (obj is String || obj is Enum) return "'" + obj.ToString() + "'";             
            if (obj is Boolean) return obj.ToString().ToLower();
            if (obj is ArrayList)
            {
                ArrayList ar = (obj as ArrayList);
                if (ar.Count == 0) return "null";
                string str = "[";
                foreach (object o in ar)
                {
                    string tmp = ToStrByType(o);
                    if (tmp.Equals("-1")) continue;
                    if (!str.EndsWith("[")) str += ",";

                    str += tmp;
                }
                if (str == "[") return "null";
                str += "]";
                return str;
            }


            return obj.ToString();
        }
    }
}
